home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Magazine / GraphicsCards / StormMesa / src / MGL / mmesa8.c < prev    next >
C/C++ Source or Header  |  1999-02-04  |  7KB  |  218 lines

  1. /****************************************************************************
  2. *
  3. *                        Mesa bindings for SciTech MGL
  4. *
  5. *               Copyright (C) 1996-1998 SciTech Software, Inc.
  6. *                            All rights reserved.
  7. *
  8. * Language:     ANSI C
  9. * Environment:    Any
  10. *
  11. * Description:    Optimized 8bpp rendering functions.
  12. *
  13. * This library is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU Library General Public
  15. * License as published by the Free Software Foundation; either
  16. * version 2 of the License, or (at your option) any later version.
  17. *
  18. * This library is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  21. * Library General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Library General Public
  24. * License along with this library; if not, write to the Free
  25. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  26. *
  27. ****************************************************************************/
  28.  
  29. #include "mgl/mmesap.h"
  30.  
  31. /*------------------------- Implementation --------------------------------*/
  32.  
  33. #pragma warn -par
  34. #include "mgl/mmesai.c"
  35.  
  36. /**********************************************************************/
  37. /*****            Write spans of pixels                           *****/
  38. /**********************************************************************/
  39.  
  40. void _mmesa_write_span_ci(GLcontext *ctx,GLuint n, GLint x, GLint y,
  41.     GLuint index[],GLubyte mask[])
  42. {
  43.     uchar *d = PACKED8_pixelAddr(x,FLIP(y));
  44.     while (n >= 8) {
  45.         if (mask[0]) d[0] = (uchar)index[0];
  46.         if (mask[1]) d[1] = (uchar)index[1];
  47.         if (mask[2]) d[2] = (uchar)index[2];
  48.         if (mask[3]) d[3] = (uchar)index[3];
  49.         if (mask[4]) d[4] = (uchar)index[4];
  50.         if (mask[5]) d[5] = (uchar)index[5];
  51.         if (mask[6]) d[6] = (uchar)index[6];
  52.         if (mask[7]) d[7] = (uchar)index[7];
  53.         d += 8; index += 8; mask += 8; n -= 8;
  54.         }
  55.     while (n--) {
  56.         if (mask[0]) d[0] = (uchar)index[0];
  57.         d++; index++; mask++;
  58.         }
  59. }
  60.  
  61. void _mmesa_write_span_ci8(GLcontext *ctx,GLuint n,GLint x,GLint y,
  62.     GLubyte index[],GLubyte mask[])
  63. {
  64.     uchar *d = PACKED8_pixelAddr(x,FLIP(y));
  65.     while (n >= 8) {
  66.         if (mask[0]) d[0] = (uchar)index[0];
  67.         if (mask[1]) d[1] = (uchar)index[1];
  68.         if (mask[2]) d[2] = (uchar)index[2];
  69.         if (mask[3]) d[3] = (uchar)index[3];
  70.         if (mask[4]) d[4] = (uchar)index[4];
  71.         if (mask[5]) d[5] = (uchar)index[5];
  72.         if (mask[6]) d[6] = (uchar)index[6];
  73.         if (mask[7]) d[7] = (uchar)index[7];
  74.         d += 8; index += 8; mask += 8; n -= 8;
  75.         }
  76.     while (n--) {
  77.         if (mask[0]) d[0] = (uchar)index[0];
  78.         d++; index++; mask++;
  79.         }
  80. }
  81.  
  82. void _mmesa_write_span_mono_ci(GLcontext *ctx,GLuint n,GLint x,GLint y,
  83.     GLubyte mask[])
  84. {
  85.     uchar *d = PACKED8_pixelAddr(x,FLIP(y));
  86.     while (n >= 8) {
  87.         if (mask[0]) d[0] = (uchar)RC.color;
  88.         if (mask[1]) d[1] = (uchar)RC.color;
  89.         if (mask[2]) d[2] = (uchar)RC.color;
  90.         if (mask[3]) d[3] = (uchar)RC.color;
  91.         if (mask[4]) d[4] = (uchar)RC.color;
  92.         if (mask[5]) d[5] = (uchar)RC.color;
  93.         if (mask[6]) d[6] = (uchar)RC.color;
  94.         if (mask[7]) d[7] = (uchar)RC.color;
  95.         d += 8; mask += 8; n -= 8;
  96.         }
  97.     while (n--) {
  98.         if (mask[0]) d[0] = (uchar)RC.color;
  99.         d++; mask++;
  100.         }
  101. }
  102.  
  103. IMPLEMENT_WRITE_SPAN(8,8,uchar);
  104. IMPLEMENT_WRITE_SPAN_DITHER(8,DITHER8,uchar);
  105. IMPLEMENT_WRITE_SPAN_RGB(8,8,uchar);
  106. IMPLEMENT_WRITE_SPAN_RGB_DITHER(8,DITHER8,uchar);
  107. IMPLEMENT_WRITE_SPAN_MONO(8,uchar);
  108. IMPLEMENT_WRITE_SPAN_MONO_DITHER(8,DITHER8,uchar);
  109.  
  110. /**********************************************************************/
  111. /*****              Write arrays of pixels                        *****/
  112. /**********************************************************************/
  113.  
  114. void _mmesa_write_pixels_ci(GLcontext *ctx,GLuint n, GLint x[],
  115.     GLint y[],GLuint index[], GLubyte mask[])
  116. {
  117.     while (n >= 4) {
  118.         if (mask[0]) *((uchar*)PACKED8_pixelAddr(x[0],FLIP(y[0]))) = (uchar)index[0];
  119.         if (mask[1]) *((uchar*)PACKED8_pixelAddr(x[1],FLIP(y[1]))) = (uchar)index[1];
  120.         if (mask[2]) *((uchar*)PACKED8_pixelAddr(x[2],FLIP(y[2]))) = (uchar)index[2];
  121.         if (mask[3]) *((uchar*)PACKED8_pixelAddr(x[3],FLIP(y[3]))) = (uchar)index[3];
  122.         index += 4; mask += 4; x += 4; y += 4; n -= 4;
  123.         }
  124.     while (n--) {
  125.         if (mask[0]) *((uchar*)PACKED8_pixelAddr(x[0],FLIP(y[0]))) = (uchar)index[0];
  126.         index++; mask++; x++; y++;
  127.         }
  128. }
  129.  
  130. void _mmesa_write_pixels_mono_ci(GLcontext *ctx,GLuint n,GLint x[],
  131.     GLint y[],GLubyte mask[])
  132. {
  133.     while (n >= 4) {
  134.         if (mask[0]) *((uchar*)PACKED8_pixelAddr(x[0],FLIP(y[0]))) = (uchar)RC.color;
  135.         if (mask[1]) *((uchar*)PACKED8_pixelAddr(x[1],FLIP(y[1]))) = (uchar)RC.color;
  136.         if (mask[2]) *((uchar*)PACKED8_pixelAddr(x[2],FLIP(y[2]))) = (uchar)RC.color;
  137.         if (mask[3]) *((uchar*)PACKED8_pixelAddr(x[3],FLIP(y[3]))) = (uchar)RC.color;
  138.         mask += 4; x += 4; y += 4; n -= 4;
  139.         }
  140.     while (n--) {
  141.         if (mask[0]) *((uchar*)PACKED8_pixelAddr(x[0],FLIP(y[0]))) = (uchar)RC.color;
  142.         mask++; x++; y++;
  143.         }
  144. }
  145.  
  146. IMPLEMENT_WRITE_PIXELS(8,8,uchar);
  147. IMPLEMENT_WRITE_PIXELS_DITHER(8,DITHER8,uchar);
  148. IMPLEMENT_WRITE_PIXELS_MONO(8,uchar);
  149. IMPLEMENT_WRITE_PIXELS_MONO_DITHER(8,DITHER8,uchar);
  150.  
  151. /**********************************************************************/
  152. /*****                 Read spans of pixels                       *****/
  153. /**********************************************************************/
  154.  
  155. void _mmesa_read_span_ci(GLcontext *ctx,GLuint n, GLint x, GLint y,
  156.     GLuint index[])
  157. {
  158.     uchar *d = PACKED8_pixelAddr(x,FLIP(y));
  159.     while (n >= 8) {
  160.         index[0] = d[0];
  161.         index[1] = d[1];
  162.         index[2] = d[2];
  163.         index[3] = d[3];
  164.         index[4] = d[4];
  165.         index[5] = d[5];
  166.         index[6] = d[6];
  167.         index[7] = d[7];
  168.         d += 8; index += 8; n -= 8;
  169.         }
  170.     while (n--) {
  171.         index[0] = d[0];
  172.         d++; index++;
  173.         }
  174. }
  175.  
  176. void _mmesa_read_span_8_8(GLcontext *ctx,GLuint n,GLint x,GLint y,
  177.     GLubyte rgba[][4])
  178. {
  179.     color_t    color,*colorTab = RC.dc->colorTab;
  180.     uchar *d = PACKED8_pixelAddr(x,FLIP(y));
  181.     while (n--) {
  182.         color = colorTab[d[0]];
  183.         UNPACK_COLOR_RGB(color,rgba[0][RCOMP],rgba[0][GCOMP],rgba[0][BCOMP]);
  184.         rgba++; d++;
  185.         }
  186. }
  187.  
  188. /**********************************************************************/
  189. /*****                   Read arrays of pixels                    *****/
  190. /**********************************************************************/
  191.  
  192. void _mmesa_read_pixels_ci(GLcontext *ctx,GLuint n, GLint x[],
  193.     GLint y[],GLuint index[], GLubyte mask[])
  194. {
  195.     while (n--) {
  196.         if (mask[0]) {
  197.             uchar *d = PACKED8_pixelAddr(x[0],FLIP(y[0]));
  198.             index[0] = d[0];
  199.             }    
  200.         index++; mask++; x++; y++;
  201.         }
  202. }
  203.  
  204. void _mmesa_read_pixels_8_8(GLcontext *ctx,GLuint n,GLint x[],GLint y[],
  205.     GLubyte rgba[][4],GLubyte mask[])
  206. {
  207.     color_t *colorTab = RC.dc->colorTab;
  208.     while (n--) {
  209.         if (mask[0]) {
  210.             uchar *d = PACKED8_pixelAddr(x[0],FLIP(y[0]));
  211.             color_t color = colorTab[d[0]];
  212.             UNPACK_COLOR_RGB(color,rgba[0][RCOMP],rgba[0][GCOMP],rgba[0][BCOMP]);
  213.             }
  214.         rgba++; mask++; x++; y++;
  215.         }
  216. }
  217.  
  218.